wfopen  "C:\Users\Maryam\Desktop\BS Studies\PhD Thesis-II\EViews and STATA Progarm Codes\Chapter-8\Malaysia.wf1"
'******************************************************************
'Group Plots for Real Exchange Rate (NT) & Productivity Gap
'******************************************************************
group gA rer_def_NT A_tilde
freeze(group_plot) gA.line(x)
group_plot.setelem(1) lcolor(black) symbol(7) lpat(1)
group_plot.setelem(2) lcolor(black) symbol(4) lpat(1)
group_plot.setelem(3) lcolor(black) symbol(1) lpat(1)
group_plot.setelem(3) lcolor(black)
group_plot.options linepat
group_plot.addtext(t) Real Exchange Rate (NT-based) and Productivity Gaps (Malaysia & U.S): 1980-2013
group_plot.addtext(b) Year
group_plot.addtext(l) PNT  
group_plot.addtext(l) NER 
group_plot.addtext(l) rer_def_NT
group_plot.addtext(r) A_TILDE
'************************************************************
'************************************************************

create y 1980 2013
'importing data from Excel for Malaysia
import  "C:\Users\Maryam\Desktop\BS Studies\PhD Thesis-II\EViews and STATA Progarm Codes\Chapter-8\Chapter 8.xlsx" range="Malaysia"

'**************************************************************************************************
'VERIFYING THE ASSUMPTION OF PPP FOR Malaysia AND U.S. TRADABLES PRICES
'**************************************************************************************************
'*************************************************************
'STEP 0: Tests for Unit Root in Individual Time Series
'*************************************************************

'***************************************************************
'Graph for Malaysia's  pT
'***************************************************************
                                        
genr pT = pT
freeze(figure_pT) pT.line
figure_pT.addtext(t) pT (Malaysia):  1980-2013
figure_pT.addtext(b) Year
figure_pT.addtext(l) pT
figure_pT.legend(off)
                                                 
'We see from the FIGURE that pT has a time trend to it.  So we would include both an intercept and a time trend in our unit root regression equtions. 

'*********************************************************************************
'ADF Unit Root Test for Malaysia's pT
'We now run our first ADF test
'**********************************************************************************
 
freeze(table_8_1_pT_adf) pT.uroot(adf,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 0.  The unit root test produces a t-value of -1.84 which is greater than our 5% criterion -3.54.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the adf test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_adf) pT.uroot(adf,const,trend,info=sic)
freeze(pT_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr pTdiff = d(pT)
freeze(figure_pTdiff) pTdiff.line
figure_pTdiff.addtext(t) DpT (Malaysia):  1980-2013
figure_pTdiff.addtext(b) Year
figure_pTdiff.addtext(l) DpT
figure_pTdiff.legend(off)

'The graph is not particularly illuminating.  Depending on how you look at it, it could have a time trend to it.  However, since the previous ADF test concluded that the equation for pT do have a time trend, we run the ADF test with both a constant as well as a time trend.

'So we begin the whole process over again: 

genr pTdiff = d(pT)
freeze(table_8_1_pTdiff1_adf) pTdiff.uroot(adf,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p =0.  The unit root test produces a t-value of -4.38 which is smaller our 5% criterion -2.94.  Thus, we may now reject the null of nonstationarity in first differenced series of pT.  There is no reason to go further.  The last thing we do is check for white noise.

genr resid = 0
freeze(mode=overwrite,pTdiff1_adf) pTdiff.uroot(adf,const,trend,info=sic)
freeze(pTdiff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT series is I(1).

'*********************************************************************************
'DF-GLS Unit Root Test for Malaysia's pT
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_1_pT_dfgls) pT.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 0.  The unit root test produces a t-value of -1.78 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr pTdiff = d(pT)
freeze(table_8_1_pTdiff1_dfgls) pTdiff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of -4.39 which is smaller than our 5% criterion -1.95.  Thus, we may now reject the null of nonstationarity in first differenced series of pT.  
 
''Putting it all together, I conclude that the pT series is I(1), a finding compatable with my ADF test results.

'***************************************************************
'Graph for Malaysia's  pT_us_PPP
'***************************************************************
                                        
genr pT_us_PPP = pT_us_PPP
freeze(figure_pT_us_PPP) pT_us_PPP.line
figure_pT_us_PPP.addtext(t) pT_us_PPP (Malaysia):  1980-2013
figure_pT_us_PPP.addtext(b) Year
figure_pT_us_PPP.addtext(l) pT_us_PPP
figure_pT_us_PPP.legend(off)
                                                 
'We see from the FIGURE that pT_us_PPP has a time trend to it.  So we would include both an intercepT_us_PPP and a time trend in our unit root regression equtions. 

'*********************************************************************************
'ADF Unit Root Test for Malaysia's pT_us_PPP
'We now run our first ADF test
'**********************************************************************************
 
freeze(table_8_1_pT_us_PPP_adf) pT_us_PPP.uroot(adf,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 0.  The unit root test produces a t-value of -1.77 which is greater than our 5% criterion -3.54.  Thus, at this point, we cannot reject the null of a unit root.

'Now, let's check for white noise.  To do that, I first set all the residuals = 0, then run the adf test and finally will check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_us_PPP_adf) pT_us_PPP.uroot(adf,const,trend,info=sic)
freeze(pT_us_PPP_adf_correl) resid.correl
 
'Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT_us_PPP series is not level stationary.

'The next thing I do is test whether the differenced series is stationary using the ADF test.  I once again begin by graphing the (differenced) series.
 
genr pT_us_PPPdiff = d(pT_us_PPP)
freeze(figure_pT_us_PPPdiff) pT_us_PPPdiff.line
figure_pT_us_PPPdiff.addtext(t) DpT_us_PPP (Malaysia):  1980-2013
figure_pT_us_PPPdiff.addtext(b) Year
figure_pT_us_PPPdiff.addtext(l) DpT_us_PPP
figure_pT_us_PPPdiff.legend(off)

'The graph is not particularly illuminating.  Depending on how you look at it, it could have a time trend to it.  However, since the previous ADF test concluded that the equation for pT_us_PPP do have a time trend, we run the ADF test with both a constant as well as a time trend.

'So we begin the whole process over again: 

genr pT_us_PPPdiff = d(pT_us_PPP)
freeze(table_8_1_pT_us_PPPdiff1_adf) pT_us_PPPdiff.uroot(adf,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p =0.  The unit root test produces a t-value of -6.41 which is smaller our 5% criterion -2.94.  Thus, we may now reject the null of nonstationarity in first differenced series of pT_us_PPP.  There is no reason to go further.  The last thing we do is check for white noise.

genr resid = 0
freeze(mode=overwrite,pT_us_PPPdiff1_adf) pT_us_PPPdiff.uroot(adf,const,trend,info=sic)
freeze(pT_us_PPPdiff1_adf_correl) resid.correl

''Based on the Q-statistic, I conclude that the residuals are white noise.  Putting it all together, I conclude that the pT_us_PPP series is I(1).

'*********************************************************************************
'DF-GLS Unit Root Test for Malaysia's pT_us_PPP
'We now run our first dfgls test
'**********************************************************************************
 
freeze(table_8_1a_pT_us_PPP_dfgls) pT_us_PPP.uroot(dfgls,trend,info=sic)

'Note that the SIC automatic lag selection picks lags, p = 0.  The unit root test produces a t-value of -1.81 which is greater than our 5% criterion -3.19.  Thus, at this point, we may not reject the null of a unit root.

'Now let's see if the series is difference stationary or not

genr pT_us_PPPdiff = d(pT_us_PPP)
freeze(table_8_1b_pT_us_PPPdiff1_dfgls) pT_us_PPPdiff.uroot(dfgls,const,info=sic)

'Note that the SIC automatic lag selection picks no lags, p = 0.  The unit root test produces a t-value of -6.48 which is smaller than our 5% criterion -1.95.  Thus, we may now reject the null of nonstationarity in first differenced series of pT_us_PPP.  
 
''Putting it all together, I conclude that the pT_us_PPP series is I(1), a finding compatable with my ADF test results.

''******************************************************************************************
''S1: Establishing Cointegration for Verifying PPP for Inter-Country Tradables Prices
'******************************************************************************************
'Now, by employing FMOLS and DOLS cointegration regression estimators, we shall calculate our LR cointegrating vectors.

equation table_8_1_LRPPP_fmols.cointreg(method=fmols) pT pT_us_PPP

equation table_8_1_LRPPP_dols.cointreg(method=dols, trend=constant, lag=1,lead=1 ) pT pT_us_PPP

'As proven by FMOLS and DOLS test results, valid cointegration holds between pT and pT_us_PPP. Thus, I can proceed with estimation of S2 condition. 

''************************************************************************************************
''S2: Testing for Equi-proportionate Relationship between Inter-Country Tradables Prices
'************************************************************************************************

freeze(table_8_1_LRPPP_fmols_Ftest) table_8_1_LRPPP_fmols.wald c(1)=1

freeze(table_8_1_LRPPP_dols_Ftest) table_8_1_LRPPP_dols.wald c(1)=1

'As proven by both Wald coefficient test results for FMOLS and DOLS estimates, PPP validly holdS for traded sector prices of Malaysia and U.S. Thus, I will not proceed with estimating the modified version of BS hypothesis.


